<?php

/**
 * This Validator checks if an user with the given name is already registered in the database 
 * @author Clueth
 *
 */

class Somi_Validate_PasswordCurrentCheck extends Zend_Validate_Abstract {

	const NOT_MATCH = 'passwordCurAssigned';
	 
	protected $_messageTemplates = array(
	self::NOT_MATCH => 'Password ist  falsch. Bitte versuchen Sie es nochmal.'
	);


	public function isValid($passwordCur) {

		 
		$passwordCur = (string) $passwordCur;
		 
		$error = false;
		 
		if(!$this->checkUnique(MD5($passwordCur))){
			$error = true;
			$this->_error(self::NOT_MATCH);
			 
		}
		else
			return !$error;
	}

	private function checkUnique($password){

		$id=$_SESSION['Zend_Auth']['storage'];
		$firma = new Somi_Models_Firma();
		$select = $firma->select()->from('firma')->where('passwort=?',$password)->where('firma_id=?',$id->firma_id);
		$result = $firma->getAdapter()->fetchOne($select);

		if($result){
			return true;
		}
		return false;
	}
	 
}

?>